<template>
	<div :class="'bg-white p-2'">
		<Row :class="'p-1'">
			<!-- <Button type="error" @click="newRole">新增</Button> -->
			<Input :class="'w-25 m-2'" v-model="searchKey" style="min-width: 200px;" placeholder="请输入角色名称" />
			
		</Row>
		<Row class="p-1">
			<Col :xs="24"
			class="p-1">
			<Button type="error" icon="md-add" shape="circle" class="m-2 float-left" @click="newRole">新增</Button>
			<Button class="m-2 float-right" type="primary" shape="circle" @click="searchs" icon="ios-search">查询</Button>
			</Col>
		</Row>
		<div class="mt-1 d-xl-none">
			<Row class="bg-white border-top border-dark">
				<Col v-for="(row, index) in tableInfo.data" :xs="24" :sm="12" :md="8" :lg="8" :xl="6" :xxl="6"
					class="p-1 mt-2">
				<div class="shadow p-3 radius text-xs text-secondary">
					<div class="p-1 d-flex justify-content-between">
						<span>角色编号</span>
						<span>{{row.roleId}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>角色名称</span>
						<span>{{row.roleName}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>状态</span>
						<span v-if="row.statu">开</span>
						<span v-else>关</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>创建时间</span>
						<span>{{row.ct}}</span>
					</div>
					<div class="p-1 d-flex justify-content-end text-sm">
						<Button type="primary"  class="m-1 float-left" @click="show(row.roleId)" ghost>详细</Button>
						<Button type="error" class="m-1 mfloat-right ml-3" @click="remove(row.roleId)" ghost>删除</Button>	
					</div>
				</div>
				</Col>
			</Row>
			
		</div>
		<div class="mt-1 d-none d-xl-block">
			<Table border :class="'m-1'" :columns="tableInfo.columnInfo" :data="tableInfo.data">
				<template slot-scope="{ row, index }" slot="status">
					<span v-if="row.statu">开</span>
					<span v-else>关</span>
				</template>
				<template slot-scope="{ row, index }" slot="action">
					<Button type="primary" size="small" style="margin-right: 5px" @click="show(row.roleId)">详细</Button>
					<Button type="error" size="small" @click="remove(row.roleId)">删除</Button>
				</template>
			</Table>
		</div>
		<div>
			<Page :class="'m-2 text-right'" :page-size="tableInfo.pageSize" @on-change="pageSearch"
				:total="tableInfo.total" />
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				searchKey: "",
				tableInfo: {
					currentPage: 1,
					total: 0,
					pageSize: 10,
					columnInfo: [{
							title: "角色编号",
							key: "roleId",
						},
						{
							title: "角色名称",
							key: "roleName",
						},
						{
							title: "状态",
							slot: "status",
						},
						{
							title: "创建时间",
							key: "ct",
						},
						{
							title: "操作",
							slot: 'action',
							width: 150
						}
					],
					data: []
				}

			};
		},
		methods: {
			init: function() {
				this.$data.tableInfo.currentPage = 0;
				this.search();
			},
			newRole: function() {
				this.$router.push({
					name: "role_new"
				});
			},
			show: function(roleId) {
				this.$router.push({
					name: "role_detail",
					params: {
						roleId
					}
				});
			},
			search: function() {
				this.http.get({
					url: "/role/list",
					param: {
						currentPage: this.$data.tableInfo.currentPage,
						roleName: this.$data.searchKey
					}
				}).then(data => {
					this.$data.tableInfo.currentPage = data.current;
					this.$data.tableInfo.total = data.total;
					this.$data.tableInfo.pageSize = data.size;
					this.$data.tableInfo.data = data.records;
				});
			},
			searchs: function() {
				this.tableInfo.currentPage = 1;
				this.search();
			},
			pageSearch: function(changedPage) {
				this.$data.tableInfo.currentPage = changedPage;
				this.search();
			},
			remove: function(roleId) {

				this.message.confirm({
					title: "删除提示",
					content: "即将删除角色，确定吗？",
					onOk: () => {
						this.http.delete({
							url: "/role/info",
							param: {
								roleId
							}
						}).then(data => {
							this.search();
						});
					},
					onCancel: () => {
						this.message.info('操作已取消');
					}
				});
			},
		},
		created: function() {
			this.init();
		},
	}
</script>

<style>
</style>
